$.ajax({
    type: 'get',
    url: '/settings',
    success: function(response) {
        $('#hiddenAvatar').val(response.logo);
        $('#preview').attr('src', response.logo);
        $('#site_name').val(response.title)
        $('#site_description').val(response.description)
        $('#site_keywords').val(response.keywords)
        $('#comment_status').prop('checked', response.comment)
        $('#comment_reviewed').prop('checked', response.review)
    }
})
$('#logo').on('change', function() {
    var file = this.files[0]
    var formData = new FormData();
    formData.append('avatar', file)
    $.ajax({
        type: 'post',
        url: '/upload',
        data: formData,
        processData: false,
        contentType: false,
        success: function(response) {
            $('#hiddenAvatar').val(response[0].avatar)
            $('#preview').attr('src', response[0].avatar);
        }
    })
})

$('#settingBtn').on('click', function() {
    $('#comment').val($('#comment_status').prop('checked'))
    $('#review').val($('#comment_reviewed').prop('checked'))
    var formData = $('#listForm').serialize()
    $.ajax({
        type: 'post',
        url: '/settings',
        data: formData,
        success: function() {
            location.reload();
            alert('修改成功')
        }
    })
    return false;
})